<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可爱任务管理器</title>
    <style>
        :root {
            --pink-1: #fff0f6;
            --pink-2: #ffdeeb;
            --pink-3: #fcc2d7;
            --pink-4: #faa2c1;
            --heart-pink: #ff85ad;
            --text-color: #4a4458;
            --border-radius: 12px;
            --shadow: 0 4px 16px rgba(255, 133, 173, 0.1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Comic Neue', cursive;
            line-height: 1.6;
            color: var(--text-color);
            background: linear-gradient(135deg, #fff5f7 0%, #ffeef2 100%);
            min-height: 100vh;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 30px 20px;
        }

        .task-creator {
            display: flex;
            gap: 15px;
            margin-bottom: 30px;
        }

        .task-input {
            flex: 1;
            padding: 18px;
            border: 3px solid var(--pink-2);
            border-radius: 50px;
            font-size: 16px;
            background: white;
            transition: all 0.3s;
            box-shadow: var(--shadow);
        }

        .task-input:focus {
            outline: none;
            border-color: var(--pink-4);
            box-shadow: 0 0 0 4px var(--pink-2);
        }

        .btn {
            padding: 16px 36px;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            font-weight: 700;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: linear-gradient(45deg, #ff85ad, #ff6b9d);
            color: white;
            text-shadow: 0 2px 2px rgba(0,0,0,0.1);
            box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(255, 107, 157, 0.4);
        }

        .btn-primary:active {
            transform: translateY(0);
        }

        .task-lists {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 25px;
        }

        .task-list {
            background: white;
            border-radius: var(--border-radius);
            overflow: hidden;
            box-shadow: var(--shadow);
            border: 3px solid var(--pink-2);
        }

        .list-title {
            padding: 18px;
            background: linear-gradient(45deg, #ff9ebb, #ff85ad);
            color: white;
            margin: 0;
            font-size: 20px;
            font-family: 'Dancing Script', cursive;
            text-align: center;
            letter-spacing: 1px;
        }

        .task-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 18px;
            border-bottom: 2px solid var(--pink-1);
            transition: all 0.3s;
            background: white;
            align-items: flex-start; /* 改为顶部对齐 */
            min-height: 60px; /* 保证最小高度 */
            padding: 15px 18px;
        }
        .task-checkbox {
            width: 24px;
            height: 24px;
            cursor: pointer;
            accent-color: var(--heart-pink);
            margin-top: 3px;
        }

        .task-text {
            /* 新增文本处理 */
            word-wrap: break-word;
            overflow-wrap: break-word;
            white-space: normal;
            /* max-width: calc(100% - 80px); 保证删除按钮可见 */
            line-height: 1.4;
            padding-right: 10px;
        }


        .delete-btn {
            background: none;
            border: none;
            color: var(--pink-4);
            cursor: pointer;
            padding: 6px;
            font-size: 20px;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: grid;
            place-items: center;
            transition: all 0.3s;
        }

        .delete-btn:hover {
            color: #ff4d6d;
            background: var(--pink-1);
        }

        @media (max-width: 600px) {
            .task-creator {
                flex-direction: column;
            }
            
            .btn {
                width: 100%;
                justify-content: center;
            }

            .task-input {
                border-radius: 30px;
            }
            .task-text {
                font-size: 14px;
            }
            .task-item {
                min-height: 50px;
                padding: 12px 15px;
            }
        }


        @import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@400;700&family=Dancing+Script:wght@600&display=swap');
    </style>
</head>
<body>
    <div class="container">
        <div class="task-creator">
            <input type="text" class="task-input" placeholder="✏️ 输入新任务..." aria-label="新任务内容">
            <button type="button" class="btn btn-primary" onclick="addTask()">
                <span>添加任务</span>
                <span>🎀</span>
            </button>
        </div>
        
        <div class="task-lists">
            <div class="task-list">
                <h3 class="list-title">待办事项</h3>
                <div class="todo-items"></div>
            </div>
            
            <div class="task-list">
                <h3 class="list-title">已完成事项</h3>
                <div class="done-items"></div>
            </div>
        </div>
    </div>

    <script>
        const taskInput = document.querySelector('.task-input');
        const todoList = document.querySelector('.todo-items');
        const doneList = document.querySelector('.done-items');

        // 创建任务元素
        // function createTaskElement(text) {
        //     const taskItem = document.createElement('div');
        //     taskItem.className = 'task-item';
        //     taskItem.innerHTML = `
        //         <input type="checkbox" class="task-checkbox">
        //         <span class="task-text">${text}</span>
        //         <button class="delete-btn">×</button>
        //     `;
        //     return taskItem;
        // }

        // 在创建任务元素时添加文本截断保护
        function createTaskElement(text) {
            const taskItem = document.createElement('div');
            taskItem.className = 'task-item';
            // 使用textContent替代innerHTML防止XSS
            taskItem.innerHTML = `
                <input type="checkbox" class="task-checkbox">
                <span class="task-text">${text.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</span>
                <button class="delete-btn">×</button>
            `;
            return taskItem;
        }

        // 处理任务状态切换
        function handleCheckboxChange(event) {
            const taskItem = event.target.closest('.task-item');
            if (event.target.checked) {
                doneList.appendChild(taskItem);
            } else {
                todoList.appendChild(taskItem);
            }
        }

        // 添加新任务
        function addTask() {
            const text = taskInput.value.trim();
            if (!text) return;

            const taskElement = createTaskElement(text);
            
            // 绑定事件
            taskElement.querySelector('.task-checkbox').addEventListener('change', handleCheckboxChange);
            taskElement.querySelector('.delete-btn').addEventListener('click', () => {
                taskElement.remove();
            });

            todoList.appendChild(taskElement);
            taskInput.value = '';
            taskInput.focus();
        }
        

        // 回车键支持
        taskInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') addTask();
        });
    </script>
</body>
</html>